import { loadModules } from 'esri-loader';
/* eslint-disable */
export default {
	/**
   * 通过中心经纬度以及缩放级别设置地图范围
   * @param map 目标地图
   * @param x x坐标
   * @param y y坐标
   * @param level 缩放级别,不填则采用当前地图级别
   * @param [wkid=4326] 地理坐标系中的GCS_WGS_1984  Web墨卡托投影坐标 102100
   */
	centerAndZoom(map: any, x: any, y: any, level?: number, wkid: number = 4326): void {
		loadModules([ 'esri/geometry/Point' ]).then(([ Point ]) => {
			if (!x || !y) {
				return;
			}
			map.centerAndZoom(new Point({ x, y, spatialReference: { wkid } }), level);
		});
	},
	/**
   * 获取地图中心点
   * @param map 目标地图
   */
	getCenter(map: any): { x: number; y: number } {
		return map.geographicExtent.getCenter();
	},

	/**
   * 添加圆
   * @param x x坐标
   * @param y y坐标
   * @param distance 辐射圈半径 单位：千米
   * @param layer 要添加到的图层对象
   * @return yuan
   */
	async addCircle(x: any, y: any, distance: any, layer: any): Promise<any> {
		const [ Point, Circle, SimpleFillSymbol, SimpleLineSymbol, Color, Graphic ] = await loadModules([
			'esri/geometry/Point',
			'esri/geometry/Circle',
			'esri/symbols/SimpleFillSymbol',
			'esri/symbols/SimpleLineSymbol',
			'esri/Color',
			'esri/graphic',
		]);
		if (!x || !y) {
			return;
		}
		const point = new Point(x, y);
		const circleGeometry = new Circle(point, {
			radius: distance * 1000,
			geodesic: true,
		});
		const sms = new SimpleFillSymbol(
			SimpleFillSymbol.STYLE_SOLID,
			new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([ 142, 229, 238 ]), 1),
			new Color([ 174, 238, 238, 0.25 ]),
		);
		// console.log(layer);
		const graphic = new Graphic(circleGeometry, sms);
		layer.add(graphic);

		return graphic;
	},
};
